package fr.efrei.tradesys.hibernate.beans;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import fr.efrei.tradesys.hibernate.factory.DaoFactory;

@Entity
@Table(name = "CURRENCY")
public class Currency
{

	private String			code;
	private String			name;
	private List<Rate>	toCurrencies;
	private List<Rate>	fromCurrencies;

	public Currency()
	{
	}

	public Currency(String code, String name)
	{
		this.code = code;
		this.name = name;
	}

	@Id
	@Column(name = "CODE", unique = true, nullable = false, length = 50)
	public String getCode()
	{
		return code;
	}

	public void setCode(String code)
	{
		this.code = code;
	}

	@Column(name = "NAME", nullable = false, length = 50)
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Transient
	public List<Rate> getToThisCurrency()
	{
		if (toCurrencies == null)
		{
			toCurrencies = DaoFactory.getInstance().getRateDao()
					.getRatesToCurrency(this);
		}
		return toCurrencies;
	}

	@Transient
	public List<Rate> getFromThisCurrency()
	{
		if (fromCurrencies == null)
		{
			fromCurrencies = DaoFactory.getInstance().getRateDao()
					.getRatesFromCurrency(this);
		}
		return fromCurrencies;
	}

}
